/* 
 * Copyright (c) 2012 JSquirrelEngine
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in 
 * the Software without restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
 * Software, and to permit persons to whom the Software is furnished to do so, subject
 * to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 */

package org.jsquirrel.geometry;

import org.jsquirrel.geometry.impl.ArrayPolygon;


/**
 * Factory for creating different kind of Polygons
 * 
 * @author Juan David Adarve Bermudez
 *
 */
public final class PolygonFactory {
	
	
	/**
	 * Creates a new Polygon instance according to the type parameter
	 * 
	 * @param type: Polygon type to be created
	 * 
	 * @return returns a new instance of Polygon of a given type
	 * 
	 * @throws IllegalArgumentException in case of unknown type
	 */
	public static final Polygon create(PolygonTypes type) {
		
		switch(type) {
			case ARRAY_POLYGON:
				return new ArrayPolygon();
			
			default:
				throw new IllegalArgumentException("PolygonFactory.create(type): unknown Polygon type");
		}
	}
	
	/**
	 * Creates a new Polygon instance according to the type parameter and with an initial
	 * number of vertices.
	 * 
	 * @param type: Polygon type to be created
	 * @param numVertices: initial number of vertices for the Polygon
	 * 
	 * @return returns a new instance of Polygon of a given type
	 * 
	 * @throws IllegalArgumentException in case of unknown type or in case numVertices is less than 0
	 */
	public static final Polygon create(PolygonTypes type, int numVertices) {
		
		if(numVertices < 0) {
			throw new IllegalArgumentException("PolygonFactory.create(type, numVertices): numVertices must be greater or equal zero: " + numVertices);
		}
		
		switch(type) {
			case ARRAY_POLYGON:
					return new ArrayPolygon(numVertices);
					
			default:
				throw new IllegalArgumentException("PolygonFactory.create(type, numVertices): unknown Polygon type");
		}
	}
}
